package com.test.net.banner;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.danikula.videocache.HttpProxyCacheServer;
import com.test.net.*;
import com.test.net.R;

import java.util.ArrayList;
import java.util.List;

public class BannerActivity extends AppCompatActivity {

    private Banner banner;
    private List<String> list;
    private Button bt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.test.net.R.layout.activity_banner);

        banner = (Banner) findViewById(R.id.banner);
        bt = (Button) findViewById(R.id.bt);

        initData();
        initView();
    }

    private void initData() {
        HttpProxyCacheServer proxy = MApplication.getProxy(getApplicationContext());

        String proxyUrl = proxy.getProxyUrl("http://www.170mv.com/tool/jiexi/ajax/pid/13214/vid/3297394.mp4");
        String proxyUrl2 = proxy.getProxyUrl("http://www.170mv.com/tool/jiexi/ajax/pid/5564/vid/2276834.mp4");

        list = new ArrayList<>();
        list.add("http://pic18.nipic.com/20120204/8339340_144203764154_2.jpg");
        list.add(proxyUrl2);
        list.add("http://pic37.nipic.com/20140110/17563091_221827492154_2.jpg");
        list.add(proxyUrl);
        list.add("http://pic15.nipic.com/20110628/1369025_192645024000_2.jpg");

    }

    private void initView() {
        banner.setDataList(list);
        banner.setImgDelyed(5000);
        banner.startBanner();
        banner.startAutoPlay();
    }

    public void onClick(View view) {

        if (view.getId() == R.id.bt) {
            HttpProxyCacheServer proxy = MApplication.getProxy(getApplicationContext());
            String proxyUrl = proxy.getProxyUrl("http://www.170mv.com/tool/jiexi/ajax/pid/13010/vid/3111376.mp4");
            String proxyUrl2 = proxy.getProxyUrl("http://www.170mv.com/tool/jiexi/ajax/pid/118/vid/2155653.mp4");

            list = new ArrayList<>();
            list.add(proxyUrl2);
            list.add("http://pic9.nipic.com/20100923/2531170_140325352643_2.jpg");
            list.add("http://pic32.nipic.com/20130902/13395269_103525238102_2.jpg");
            list.add(proxyUrl);
            list.add("http://pic40.nipic.com/20140331/9469669_142840860000_2.jpg");
        } else {
            list = new ArrayList<>();
        }
        banner.dataChange(list);
    }

    @Override
    protected void onDestroy() {
        banner.destroy();
        super.onDestroy();
    }
}
